package hu.crs.game.entity.creature;

import hu.crs.game.action.move.Movement;
import hu.crs.game.entity.Entity;

public abstract class Creature extends Entity {
	private static final long serialVersionUID = -7662885663791798813L;
	
	private int maxHp;
	private int hp;
	//The hp regeneration value of creature in case of regeneration
	private int hpRegenerationValue;
	//Creature regenerates hp in case of hpRegenerationCounter reaches this value
	private int hpRegenerationRate;
	private int hpRegenerationCounter = 0;
	
	//number of grids which a creature can move in case of move is triggered
	private int speed;
	// in case of moveConter reaches this value creature is enabled to move
	private float moveRate;
	private int moveCounter=0;

	public int getHp() {
		return hp;
	}

	protected void init(int maxHp, int hpRegenerationValue,
			int hpRegenerationRate, int speed, float moveRate) {
		this.maxHp=maxHp;
		this.hpRegenerationValue=hpRegenerationValue;
		this.hpRegenerationRate=hpRegenerationRate;
		this.speed=speed;
		this.moveRate=moveRate;
	}

	public int lowerHp(int number) {
		hp -= number;
		return hp;
	}

	public void regenerate() {
		if (hpRegenerationCounter >= hpRegenerationRate) {
			hp += hpRegenerationValue;
			if (hp >= maxHp) {
				hp = maxHp;
			}
			hpRegenerationCounter = 0;
		}
		hpRegenerationCounter++;
	}
	
	public Movement move() {
		Movement mo = new Movement(false, 0);
		if (moveCounter>=moveRate) {
			mo.setMove(true);
			mo.setValue(speed);
			moveCounter=0;
		}
		return mo;
	}
}
